/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horizon.entity;

import horizon.animations.AnimationCache;
import horizon.collision.CollisionManager;
import horizon.component.AnimationRender;
import horizon.util.Vector2;

/**
 *
 * @author J_Laptop
 */
public class Player extends CollidingEntity {

    int health = 100;
    Vector2 lastMov = new Vector2(0);

    public int getHealth() {
        return health;
    }

    public Player(String id, CollisionManager c) {
        super(id, c);

        this.AddComponent(new AnimationRender("Render"));
        ((AnimationRender) this.getComponent("Render")).setAnimation(AnimationCache.playerIdle);
        speed = 10;

    }

    @Override
    public void onCollide() {
    }

    public void doDamage(int damage) {

        health -= damage;
        if (health <= 0) {

            System.out.println(this + " is dead");

        }

    }

    public void move(Vector2 v) {

        super.move(v);
        lastMov = v;

    }

    public Vector2 movePlayer(String s) {
        Vector2 v = new Vector2(0);

        switch (s) {

            case "left":
                v = new Vector2(-1, 0);

                break;
            case "right":
                v = new Vector2(1, 0);

                break;
            case "forward":
                v = new Vector2(0, -1);

                break;
            case "back":
                v = new Vector2(0, 1);

                break;
            case "none":
                v = new Vector2(0);

                break;
        }
        movePlayer(v);

        return v;
    }

    public void movePlayer(Vector2 v) {

        AnimationRender r = ((AnimationRender) this.getComponent("Render"));

        if (v.equals(new Vector2(-1, 0))) {
            r.setAnimation(AnimationCache.playerWalkLeft);
        } else if (v.equals(new Vector2(1, 0))) {
            r.setAnimation(AnimationCache.playerWalkRight);
        } else if (v.equals(new Vector2(0, -1))) {
            r.setAnimation(AnimationCache.playerWalkForward);
        } else if (v.equals(new Vector2(0, 1))) {
            r.setAnimation(AnimationCache.playerWalkBack);
        } else if (v.equals(new Vector2(0))) {

            r.setAnimation(AnimationCache.playerIdle);
        }

        lastMov = v;
        move(v);

    }

    public Vector2 getLastMov() {
        return lastMov;
    }
}
